package com.rcl.himalaya_kotlin

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.rcl.himalaya_kotlin.adapter.TitleFragmentPagesAdapter
import com.rcl.himalaya_kotlin.fragment.CollectionFragment
import com.rcl.himalaya_kotlin.fragment.RecommendFragment
import com.rcl.himalaya_kotlin.fragment.SubscriptionFragment
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setTab()
        setItem()
    }

    //设置Tab
    private fun setTab() {
        val tab1 = RecommendFragment()
        val tab2 = SubscriptionFragment()
        val tab3 = CollectionFragment()
        val list = listOf(tab1, tab2, tab3)

        vp_content.adapter = TitleFragmentPagesAdapter(list, supportFragmentManager)
        tl_table.setupWithViewPager(vp_content)
    }

    private fun setItem() {
        val list = listOf("推荐", "订阅", "收藏")
        tl_table.getTabAt(0)?.text = list[0]
        tl_table.getTabAt(1)?.text = list[1]
        tl_table.getTabAt(2)?.text = list[2]
    }

}